import { bind } from "../../core/module/proxy/ProxyDecorator";
import { RegisterProxy } from "../../script/proxy/RegisterProxy";
import { app } from "../../script/app/App";
import { UIBase } from "../../core/module/ui/UIBase";
import { SceneEnum } from "../../script/share/Enum";
@bind(RegisterProxy)
export class Register extends UIBase<RegisterProxy> {
    onInit(): void {
        this._view.btnClose.onClick(this, this._onCloseClick)
        this._view.btnRegister.onClick(this, this._onRegisterClick)
    }

    private _onRegisterClick() {
        const account = this._view.inputAccount.string
        if (!account) {
            app.toast.showTips('请输入账号')
            return
        }
        const password = this._view.inputPassword.string
        if (!password) {
            app.toast.showTips('请输入密码')
            return
        }
        const confirmPassword = this._view.confirmPassword.string
        if (!confirmPassword) {
            app.toast.showTips('请输入确认密码')
            return
        }
        if (password != confirmPassword) {
            app.toast.showTips('密码不一致')
            return
        }
        app.model.login.accountRegisterReq(account, password, () => app.scene.startScene(SceneEnum.Lobby))
    }

    private _onCloseClick() {
        app.ui.close(RegisterProxy)
    }

}